package com.wechat.common;

import com.alibaba.druid.filter.stat.StatFilter;
import com.alibaba.druid.wall.WallFilter;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.wechat.common.route.AdminRoutes;
import com.wechat.common.route.FrontRoutes;
import com.wechat.common.route.WechatRoutes;

public class MainConfig extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		PropKit.use("main_config.txt");
		me.setDevMode(PropKit.getBoolean("devMode", false));
		me.setEncoding("UTF-8");
        me.setBaseViewPath("/view");
	}
	
	@Override
	public void configInterceptor(Interceptors me) {
		//拦截器
	}
	
	public static DruidPlugin creatDruidPliugin(){
        return new DruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
    }
	
	@Override
	public void configPlugin(Plugins me) {
		//插件
		//配置druid数据库连接池插件(配置数据库信息后再解开)
//        DruidPlugin dp = creatDruidPliugin();
//        dp.addFilter(new StatFilter());
//        WallFilter wall = new WallFilter();
//        wall.setDbType("mysql");
//        dp.addFilter(wall);
//        me.add(dp);
//
//        // 配置ActiveRecord插件
//        ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
//        arp.setShowSql(true);
//        me.add(arp);
//
//        // 所有数据库映射配置在 MappingKit 中搞定
//        _MappingKit.mapping(arp);
	}
	
	@Override
	public void configRoute(Routes me) {
		//路由
		me.add(new FrontRoutes());//前端路由
		me.add(new AdminRoutes());//后端路由
		me.add(new WechatRoutes());//微信路由
	}
	
	@Override
	public void configHandler(Handlers me) {

	}
	
	public static void main(String[] me) {
		JFinal.start("WebRoot", 8081, "/", 5);
	}

}
